FROM php:7.4.3

RUN  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN  apt-get clean


RUN apt-get update \
    && apt-get install -y \
    curl wget git zip unzip less vim procps lsof tcpdump htop openssl \
    libz-dev \
    libssl-dev \
    libnghttp2-dev \
    libpcre3-dev \
    libjpeg-dev \
    libpng-dev \
    libfreetype6-dev \
    vim 

ENV SWOFT_CLI_VERSION=0.2.0\
    SWOOLE_VERSION=4.4.16 \
    TIMEZONE=${timezone:-"Asia/Shanghai"}\
    PHPREDIS_VERSION=5.1.0

RUN php -m&& docker-php-ext-install -j$(nproc) bcmath calendar  gettext \
    sockets pdo_mysql 

# 1.0.5 增加 GD 扩展. 图像处理
# RUN apt-get update && \
#     apt-get install -y --no-install-recommends libfreetype6-dev libjpeg62-turbo-dev libpng-dev && \
#     rm -r /var/lib/apt/lists/* && \
#     docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
#     docker-php-ext-install -j$(nproc) gd

RUN  wget -c http://pecl.php.net/get/redis-${PHPREDIS_VERSION}.tgz -O /tmp/redis.tar.tgz \
    && pecl install /tmp/redis.tar.tgz \
    && rm -rf /tmp/redis.tar.tgz \
    && docker-php-ext-enable redis


RUN wget -c https://getcomposer.org/installer\
    && php installer\
    && mv composer.phar /usr/local/bin/composer\
    && chmod +x /usr/local/bin/composer\
    #Install swoole extension
    && apt-get clean \
    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
    # Timezone
    && cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
    && echo "${TIMEZONE}" > /etc/timezone \
    && echo "[Date]\ndate.timezone=${TIMEZONE}" > /usr/local/etc/php/conf.d/timezone.ini

RUN wget -c https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz \
    && mkdir -p swoole \
    && tar -xf swoole.tar.gz -C swoole --strip-components=1 \
    && rm swoole.tar.gz \
    && ( \
    cd swoole \
    && phpize \
    && ./configure --enable-mysqlnd --enable-sockets --enable-openssl --enable-http2 \
    && make -j$(nproc) \
    && make install \
    ) \
    && rm -r swoole \
    && docker-php-ext-enable swoole

RUN wget -c https://github.com/swoft-cloud/swoft-cli/releases/download/v${SWOFT_CLI_VERSION}/swoftcli.phar \
    && mv swoftcli.phar /usr/local/bin/swoftcli && chmod a+x /usr/local/bin/swoftcli\
    && swoftcli -V